package com.freesky.web.portal.controller;

import com.freesky.common.vo.VOCommon;
import com.freesky.common.vo.portal.VOMember;
import com.freesky.common.vo.VOMemberLoginRegist;
import com.freesky.common.pojo.Result;
import com.freesky.web.portal.reomte.MemberRemote;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Freesky
 */
@RestController
@Api(description = "会员注册登录")
public class MemberController {
    @Autowired
    private MemberRemote memberRemote;

    @GetMapping(value = "/member/geetest-init")
    @ApiOperation(value = "极验初始化")
    public String geetesrInit() {
        return memberRemote.geetesrInit();
    }

    @PostMapping(value = "/member/login")
    @ApiOperation(value = "用户登录")
    public Result<VOMember> login(@RequestBody VOMemberLoginRegist memberLoginRegist) {
        return memberRemote.login(memberLoginRegist);
    }

    @GetMapping(value = "/member/login/check")
    @ApiOperation(value = "判断用户是否登录")
    public Result<VOMember> checkLogin(@RequestParam(value = "token",defaultValue = "") String token) {
        return memberRemote.checkLogin(token);
    }

    @GetMapping(value = "/member/logout")
    @ApiOperation(value = "退出登录")
    public Result<Object> logout(@RequestParam(value = "token",defaultValue = "") String token) {
        return memberRemote.logout(token);
    }

    @GetMapping(value = "/member/register")
    @ApiOperation(value = "用户注册")
    public Result<Object> register(@RequestBody VOMemberLoginRegist memberLoginRegist, HttpServletRequest request) {
        return memberRemote.register(memberLoginRegist, request);
    }

    @GetMapping(value = "/member/image/upload")
    @ApiOperation(value = "用户头像上传")
    public Result<Object> imgaeUpload(@RequestBody VOCommon common) {
        return memberRemote.imgaeUpload(common);
    }
}
